#ifndef __EVENTLOOP_THREAD_H__
#define __EVENTLOOP_THREAD_H__
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <string>

using std::thread;
using std::mutex;
using std::condition_variable;
using std::string;

class EventLoop;
class EventLoopThread
{
public:
    typedef std::function<void(EventLoop*)> ThreadInitCallback ;
    EventLoopThread(const ThreadInitCallback &cb = ThreadInitCallback(),
                    const string &name = string());
    ~EventLoopThread();
    EventLoop *startLoop(); // 获取事件循环 如果EventLoop还未创建则阻塞等待
private:
    void threadFunc(); // 创建一个EventLoop 通过startLoop获取然后启动循环
    EventLoop *_loop;
    bool _exiting;
    thread _thread;
    mutex _mutex;
    condition_variable _cond;
    ThreadInitCallback _callback;
};

#endif